package com.lib.controller;

import com.lib.service.BaseWxService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by duqingxiang on 17/5/24.
 */
public abstract class AbstractScopeController {

    protected abstract BaseWxService getWXService();

    public String getOpenId(HttpServletRequest request){

        String code = request.getParameter("code");
        try {
            WxMpOAuth2AccessToken token = this.getWXService().oauth2getAccessToken(code);

            if (token == null) {
                return null;
            }

            return token.getOpenId();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}
